package com.ytzl.itrip.common;

import com.alibaba.fastjson.JSON;
import com.ytzl.itrip.pojo.ItripUser;

/**
 * Created by sam on 2018/2/9.
 */
public class ValidationToken {
    private RedisAPI redisAPI;

    public void setRedisAPI(RedisAPI redisAPI) {
        this.redisAPI = redisAPI;
    }

    /**
     * 获取当前用户
     *
     * @param token
     * @return
     */
    public ItripUser getCurrentUser(String token) {
        if (token == null || token == "")
            return null;
        //用户信息json
        String itripUserJson = redisAPI.get(token);
        //解析
        ItripUser itripUser = JSON.parseObject(itripUserJson, ItripUser.class);
        return itripUser;
    }
}
